//渠道
/*belongFunction()
function belongFunction() {
    $.ajax({
        type: "post",
        url: root.member.getGroup,
        cache: false,  //禁用缓存
        dataType: "json",
        data: {
        },
        success: function (data) {
            console.log(data)
            if(data.errorCode=="0") {
                var dataInter=data.group;
                var interText = doT.template($("#ascription_bob").text());
                $("#ascription_lsit").html(interText(dataInter));
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });


}*/

function  chooseProject(){
    var chooseData={
        "projectId":$("#projectId").val(), //项目编码
        "projectName":$("#projectName").val(), //项目名称
        "projectBelongName":$("#projectBelongName").val(),//所属分公司
        "receiverCompanyName":$("#receiverCompanyName").val(),//收货公司名称
        "invoiceCompanyName":$("#invoiceCompanyName").val(),//开票公司名称
    };
    localStorage.setItem("chooseData",JSON.stringify(chooseData));
    layer_show('选择渠道','chooseChannel.html', 1200, 445);
}
//保存
function addchannel(){
        console.log(typeof($("#tuan").val()));
        if($("#tuan").val()==''){
            $.Huimodalalert("录入必填信息！",2000);
            return false;
        }
    if($("#interfaceType").val()==''){
        $.Huimodalalert("录入必填信息！",2000);
        return false;
    }
    if($("#customerStatus").val()==''){
        $.Huimodalalert("录入必填信息！",2000);
        return false;
    }
        $.ajax({
            url:root.dockingplatform.addForView,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            contentType: "application/json",
            data: JSON.stringify({
                "customerId": $("#customerId").val(),
                "customerCode": $("#customerCode").val(),
                "customerName": $("#customerName").val(),
                "customerBelong": $("#tuan").val(),
                "interfaceType": $("#interfaceType").val(),
                "customerStatus": $("#customerStatus").val(),
                "customerPlatform": $("#projectName").val(),
                "description": $("#projectBelongName").val(),
            }),
            success: function (data) {
                if(data.errorCode==0){
                    showmsg("保存成功",6);
                }else {
                    $.Huimodalalert(data.msg,2000);
                }
            },
            error: function () {
                $.Huimodalalert('保存失败！',2000);
            }
        })
}

// 提示信息
function showmsg(msg,icon){
    layer.msg(msg, {
        icon:icon,
        time: 1000
    },function(){
        if(icon==6){
            var index = parent.location.reload();
            parent.layer.close(index);
        }
    });
}

function getChannelCode(){
        var aa=document.getElementById("customerId").value;
        document.getElementById("customerCode").value = aa;
        // if($("#customerId").val().length<10 && $("#customerId").val()!=""){
        //     $.Huimodalalert('客户ID最少要输入10个字符！',2000);
        //     return false;
        // }
        /*$.ajax({
            url:root.dockingplatform.listChannelConfig,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            contentType: "application/json",
            data: JSON.stringify({
                "pageNum":1,
                "pageSize":10,
                "customerId":$("#customerId").val(),
                "customerName":$("#customerName").val(),
            }),
            success: function (data) {
                console.log(data)
                //couponlist(data.data.result);
                if (data.data.result.length>1){
                    $("#customerCode").val("")
                }else if(data.data.result.length==0){
                    $("#customerCode").val("")
                }else{
                    $("#customerCode").val(data.data.result[0].customerCode)
                }
            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        });*/
}
//运营经理关联
belongFunction();
function belongFunction(){
    //销售经理

    var manager=$("#organization_name").val();
    var user_data = {
        "pageNum":1,

        "pageSize":20,

    }
    var succCallBack = function (data, status, response) {
        console.log(data)
        if(data.errorCode=="0"){
            var jsonObj =data.group;
            if(jsonObj==""){
                $("#tuan").html("<option>无数据</option> ");
            }else {
                console.log(jsonObj)

                var optionstring = "<option value=\"\" selected>请选择</option>";
                for (var  i= 0; i < jsonObj.length; i++) {
                    optionstring += "<option onclick='relation("+ jsonObj[i].id+",\""+jsonObj[i].organization_name+"\")' data-align=\"" + jsonObj[i].id + "\" > " + jsonObj[i].organization_name + "</option>";
                }
                $("#tuan").html(optionstring);
                console.log(jsonObj)
            }
        }else{
            $("#tuan").html("<option>无数据</option> ");
        }
    }
    /*root.member.getGroup*/
    web.doAjax(root.member.getGroup,'post',user_data, succCallBack);

}
/*
//取光标
$("#organization_name").focus(function () {
    $("#tuan").show()
});
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tuan").length == 0 && $(e.target).closest("#organization_name").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tuan").hide()
    }
})
function relation(id,ce) {
    $("#organization_name").val(ce).text(id)
    $("#tuan").hide()
    console.log($("#organization_name").text())
}*/
